#!/bin/bash

# == Using Escape Character to Print Nice ==
# printf is very flexible and makes report printing job relatively easier
# by allowing you to print the output in the way you want it.

# syntax:
#   printf "print format", variable1, variable2, etc.
#
#   Special character           Description
#       \n                      new line 
#       \t                      tab 
#       \v                      vertical tab
#       \b                      backspace
#       \r                      carriage return
#       \f                      form feed

awk -f ./08_pretty_print.awk


# == Print User OFS, ORS Values == 
# when you print multiple values separated by comma using print command
# , it uses the OFS and RS built-in variable values to decide how to
# print the fields

awk -f ./08_print_user_ofs_ors.awk ./test_items.txt
echo -e '\n'

# NOTE: printf function doesn't use OFS, ORS values, it uses only what 
# is specified in the "format" parametter


# == printf with fiexed column width
# to create a fixed width report, you have to specify a number immediately
# after the % in the format specifier. This number indicates the minimum
# number of character to be printed.
# 
# when the input-string is smaller than the specified number, spaces are
# added to the left to make it fixed width.

# printf format specifiers
# specifiers    Description
# s             String
# c             Single Character
# d             Decimal
# e             Exponential floating number
# g             Uses either e or f depending on whitch is smaller for
#               given input 
# o             Octal
# x             Hexdecimal
# %             Prints the percentage synmbol

awk -f ./08_printf_fixed_width.awk ./test_items.txt
echo -e '\n'

# == Left Justified & Right justified ==
# * printf "|%6s|\n", "Good"
#      | Good|
# * printf "|%-6s|\n", "Good"
#      |Good |
sed 's/%/%-/g ' ./08_printf_fixed_width.awk | awk -f - ./test_items.txt
echo -e '\n'

